//
//  AboutMIDIViewController.m
//  CommunityNannyO2O
//
//  Created by 90 on 15/7/21.
//  Copyright (c) 2015年 Apple. All rights reserved.
//

#import "AboutMIDIViewController.h"
#import "AppConfig.h"
#import "QXNetWorkTool.h"
#import "APIAdress.h"
#import "MBProgressHUD+YC.h"
#import "MJExtension.h"
#import "AccountTool.h"
#import "AboutMIDIViewCell.h"
#import "AboutMIDISubWebViewController.h"
#import "AboutMIDIModel.h"

@interface AboutMIDIViewController()<QXNetWorkToolDelegate,
        UITableViewDataSource,UITableViewDelegate,
        AboutMIDIViewCellDeletage>
{

}

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic)  NSMutableArray *data;
@property (copy, nonatomic) NSString *title;
@property (copy, nonatomic) NSString *articleId;

@end


@implementation AboutMIDIViewController

@synthesize data;

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.tableView.dataSource = self;
    
    self.tableView.delegate = self;
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    self.data = [[NSMutableArray alloc]init];
    
    [self.data addObject:@{@"北京迷笛音乐学校": @"music_school"}];
    [self.data addObject:@{@"迷笛音乐节" : @"music_festival"}];
    [self.data addObject:@{@"太湖迷笛营" : @"taihu_midi"}];
    [self.data addObject:@{@"迷笛全国音乐考级": @"modern_music"}];
    [self.data addObject:@{@"中国摇滚迷笛奖": @"rock_midi"}];
    [self.data addObject:@{@"迷笛音乐俱乐部": @"midi_club"}];
    [self.data addObject:@{@"孩子们的迷笛": @"children_midi"}];
    [self.data addObject:@{@"迷笛出品": @"midi_produce"}];
    [self.data addObject:@{@"北京国际爵士音乐节": @"beijing_jazz"}];
    [self.data addObject:@{@"迷笛电子音乐节": @"electronic_music"}];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return 1;
}


-(void)setWeb:(int)tag
{
    NSDictionary *dic = [self.data objectAtIndex:tag - 1];
    
    self.title = [[dic allKeys] objectAtIndex:0];
    self.articleId = [[dic allValues] objectAtIndex:0];
    
    [MBProgressHUD showMessage:@"正在加载" toView:self.view];
    QXNetWorkTool *tool = [[QXNetWorkTool alloc]init];
    
    tool.QXNetWorkDelegate = self;
    
    [tool GetDataFromServerWithPostMethodandInterfaceName:AboutMIDIInterface 	andParameter:@[@{@"article_id":self.articleId}] tag:1];
}

- (void)GetFailResponse:(id)Response andTag:(int)tag
{
    [MBProgressHUD hideHUDForView:self.view];
    
    if (Response == nil)
        return;
    
    NSString *message = Response;
    
    [MBProgressHUD showError:message toView:self.view];
    
}

- (void)GetSuccessMessage:(id)message andTag:(int)tag
{
    
    NSString *mes = message;
    
    switch (tag)
    {
        case 1:
//            [MBProgressHUD showSuccess:mes toView:self.view];
            break;
    }
}


-(void)GetSuccessResponse:(id)Response andTag:(int)tag
{
    [MBProgressHUD hideHUDForView:self.view];
    if (Response == nil)
    {
        return;
    }
    switch (tag)
    {
        case 1:
        {
            AboutMIDIModel *model;
            for (NSDictionary *dic in Response)
            {
                model = [AboutMIDIModel AboutMIDIModelWithDict:dic];
                break;
            }
            
            AboutMIDISubWebViewController *obj = [AboutMIDISubWebViewController create];
            obj.title = self.title;
            obj.url = model.url;
            
            [self.navigationController pushViewController:obj animated:YES];
        }
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 906;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    AboutMIDIViewCell *cell = [AboutMIDIViewCell cellWithTableView:tableView];
    cell.aboutMIDIViewCellDeletage = self;
    
    return cell;
}

-(void)configNavigationItem
{
    self.navigationItem.title = @"关于迷笛";
    [self.navigationController.navigationBar setTranslucent:NO];
    
    [self.navigationController.navigationBar
     setBackgroundImage:[UIImage imageNamed:@"bg_navigation_bar"]
     forBarMetrics:UIBarMetricsDefault];
    
    //status bar的字体为白色
    //导航栏的背景色是黑色
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName, [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0],UITextAttributeTextShadowColor,[UIFont fontWithName:@"Hiragino Sans GB" size:18.0],NSFontAttributeName,nil]];
    
    [self configNavigationBackAction:^{
        
        [self.navigationController popViewControllerAnimated:YES];
    }];
}

-(void)useMethodToFindBlackLineAndHind
{
    UIImageView* blackLineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
    
    blackLineImageView.hidden = YES;
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];

    [self configNavigationItem];

    [self useMethodToFindBlackLineAndHind];
}

-(void)viewWillDisappear:(BOOL)animated
{

}


@end








